package com.xrz.sxm.aj.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.xrz.sxm.aj.activity.R;
import com.xrz.sxm.aj.utils.DisplayUtil;
import com.xrz.sxm.aj.utils.ScreenUtil;

public class TouchImageView extends ImageView {

	private Paint m_Paint;
	private int m_Res;

	private boolean isSelect = false;
	private Drawable m_Drawable;
	private int m_DisWidth, m_DisHight;
	private int x, y;
	private int width, hight;
	private String text = "";

	public TouchImageView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	public TouchImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public TouchImageView(Context context) {
		super(context);
		init();
	}

	private void init() {
		m_Paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		m_Paint.setColor(Color.WHITE);
		m_Paint.setTextSize(DisplayUtil.sp2px(getContext(), 14));
		m_DisWidth = ScreenUtil.getInstant().getDisWidth(getContext());
		m_DisHight = ScreenUtil.getInstant().getDisHight(getContext());
	}

	@Override
	public void setImageResource(int resId) {
		super.setImageResource(resId);
		m_Res = resId;
		m_Drawable = getContext().getResources().getDrawable(resId);
		width = m_Drawable.getIntrinsicWidth();
		hight = m_Drawable.getIntrinsicHeight();
		checkPosition();
	}

	private void checkPosition() {
		switch (m_Res) {
			case R.mipmap.bo_bo_tou1_sel:
			case R.mipmap.bo_bo_tou2_sel:
				x = width / 2+DisplayUtil.dip2px(getContext(), 25);
				y = DisplayUtil.dip2px(getContext(), 25);
				text = "头部";
				break;

			case R.mipmap.bo_bo_fro_sel:
			case R.mipmap.bo_bo_bak_sel:
				x = width / 2+DisplayUtil.dip2px(getContext(), 25);
				y = DisplayUtil.dip2px(getContext(), 25);
				text = "全身";
				break;
			case R.mipmap.bo_bo_fu_sel:
				x = width / 2 + DisplayUtil.dip2px(getContext(), 25);
				y = hight / 2 - DisplayUtil.dip2px(getContext(), 45);
				text = "腹部";
				break;
			case R.mipmap.bo_bo_jian1_sel:
			case R.mipmap.bo_bo_jian2_sel:
				x = width / 2 + DisplayUtil.dip2px(getContext(), 45);
				y = DisplayUtil.dip2px(getContext(), 77);
				text = "肩部";
				break;
			case R.mipmap.bo_bo_jing1_sel:
			case R.mipmap.bo_bo_jing2_sel:
				x = width / 2 + DisplayUtil.dip2px(getContext(), 22);
				y = DisplayUtil.dip2px(getContext(), 65);
				text = "颈部";
				break;
			case R.mipmap.bo_bo_shou1_sel:
			case R.mipmap.bo_bo_shou2_sel:
				text = "手部";
				x = width / 2 + DisplayUtil.dip2px(getContext(), 50);
				y = DisplayUtil.dip2px(getContext(), 80);
				break;
			case R.mipmap.bo_bo_tui1_sel:
			case R.mipmap.bo_bo_tui2_sel:
				text = "腿部";
				x = width / 2 + DisplayUtil.dip2px(getContext(), 38);
				y = hight / 2;
				break;
			case R.mipmap.bo_bo_xiong_sel:
				text = "胸部";
				x = width / 2 + DisplayUtil.dip2px(getContext(), 36);
				y = DisplayUtil.dip2px(getContext(), 100);
				break;
			case R.mipmap.bo_bo_yin_sel:
				text = "二阴部";
				x = width / 2 + DisplayUtil.dip2px(getContext(), 14);
				y = hight / 2 - DisplayUtil.dip2px(getContext(), 10);
				break;

			case R.mipmap.bo_bo_bei_sel:
				text = "背部";
				x = width / 2 + DisplayUtil.dip2px(getContext(), 33);
				y = DisplayUtil.dip2px(getContext(), 120);
				break;
			case R.mipmap.bo_bo_gang_sel:
				text = "肛门直肠部";
				x = width / 2 + DisplayUtil.dip2px(getContext(), 14);
				y = hight / 2 - DisplayUtil.dip2px(getContext(), 10);
				break;
			case R.mipmap.bo_bo_yao_sel:
				x = width / 2 + DisplayUtil.dip2px(getContext(), 30);
				y = hight / 2 - DisplayUtil.dip2px(getContext(), 55);
				text = "腰部";
				break;
		}
	}

	public void setSelect(boolean isSelect) {
		this.isSelect = isSelect;
		invalidate();
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		if (isSelect) {
			canvas.drawText(text, x, y, m_Paint);
		} else {
			canvas.drawText("", m_DisWidth / 2, m_DisHight / 2, m_Paint);
		}
	}

}
